//
//  DCButton.m
//  JiuyaoDriver
//
//  Created by 大橙子 on 2018/11/22.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCButton.h"
#define IWTabBarButtonImageRatio 0.5
// 按钮的默认文字颜色
#define BZGTabBarButtonTitleColor UIColorFromRGB(0x666666)
// 按钮的选中文字颜色


@implementation DCButton
-(void)setBtn
{
    CGFloat height = self.height * 2/3;
    UILabel *labNum = [[UILabel alloc]initWithFrame:CGRectMake(0,self.height/6, self.width, height*2/3)];
    //    labNum.backgroundColor = [UIColor whiteColor];
    labNum.textAlignment = NSTextAlignmentCenter;
    labNum.textColor = DCColor(127, 196, 152);
    labNum.font = [UIFont systemFontOfSize:28];
    self.labNum = labNum;
    [self addSubview:labNum ];
    
    UILabel *labText = [[UILabel alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(labNum.frame), self.width, height*1/3)];
    //    labText.backgroundColor = [UIColor whiteColor];
    labText.textAlignment = NSTextAlignmentCenter;
    labText.textColor = DCColor(134, 134, 134);
    labText.font = [UIFont systemFontOfSize:14];
    self.labText = labText;
    [self addSubview:labText ];
}

+ (DCButton *)buttonWithFrame:(CGRect)frame title:(NSString *)title image:(NSString *)image tag:(NSInteger)tag
{
    DCButton *btn = [DCButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    btn.tag = tag;
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    btn.titleLabel.font = FONT(15);
    return btn;
}
-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 图标居中
        self.imageView.contentMode = UIViewContentModeCenter;
        // 文字居中
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        // 字体大小
        self.titleLabel.font = [UIFont boldSystemFontOfSize:15];
        // 文字颜色
        [self setTitleColor:BZGTabBarButtonTitleColor forState:UIControlStateNormal];
        [self setTitleColor:BlueColor forState:UIControlStateSelected];
        
        
    }
    return self;
    
}
//// 重写去掉高亮状态
//- (void)setHighlighted:(BOOL)highlighted {}

// 内部图片的frame
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat imageW = contentRect.size.width;
    CGFloat imageH = contentRect.size.height * IWTabBarButtonImageRatio;
    return CGRectMake(0, 13*HEIGHTSCALE6, imageW, imageH);
}

// 内部文字的frame
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    CGFloat titleY = contentRect.size.height * 0.55;
    CGFloat titleW = contentRect.size.width;
    CGFloat titleH = 30;
    return CGRectMake(0, titleY+4, titleW, titleH);
}

//异常填写页面的按钮
+ (UIButton *)buttonWithtitle:(NSString *)title
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.titleLabel.font = FONT(14);
    [button setBackgroundImage:[DCTool getImageForColor:BlueColor] forState:UIControlStateSelected];
    [button setBackgroundImage:[DCTool getImageForColor:[UIColor whiteColor]] forState:UIControlStateNormal];
    button.layer.cornerRadius = 5;
    button.layer.masksToBounds = YES;
    button.layer.borderWidth = 1;
    button.layer.borderColor =BlueColor.CGColor;
    
    return button;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
